package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.education.AddEducationDto;
import com.team.recruitment_management_system.pojo.entity.EducationExperience;
import com.team.recruitment_management_system.service.EducationExperienceService;
import com.team.recruitment_management_system.util.result.Result;
import com.team.recruitment_management_system.util.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * time 2024.3.27
 * author xxxty
 */
@RestController
@RequestMapping("/sys/education")
@Tag(name = "教育经历模块")
public class EducationExperienceController {

    @Autowired
    EducationExperienceService educationExperienceService;

    @PostMapping("/update")
    @Operation(summary = "更新教育经历表")
    public Result update(@RequestBody EducationExperience educationExperience,@RequestHeader String authorization){
        Integer i = educationExperienceService.update(educationExperience, authorization);
        return i>0?Result.ok(null,"修改成功"):Result.build(null, ResultCodeEnum.ILLEGAL_OPERATION);
    }

    @GetMapping("/findMine")
    @Operation(summary = "查找自己的教育经历")
    Result findOne(@RequestHeader String authorization){
        return Result.ok(educationExperienceService.findMyEducationExperience(authorization));
    }

    @GetMapping("/findByEducationId/{id}")
    @Operation(summary = "根据教育经历id查找教育经历",security = {@SecurityRequirement(name = "Authorization")})
    Result findOneByeEducationId(@PathVariable int id){
        return Result.ok(educationExperienceService.getById(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增教育经历",security = {@SecurityRequirement(name = "Authorization")})
    Result add(@RequestBody @Validated AddEducationDto educationDto){
        return educationExperienceService.addOne(educationDto);
    }
}
